#include <bits/stdc++.h>
#define int long long
#define ls tree[x].lson
#define rs tree[x].rson
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int t,n,m,ed,V,st,b[100001],chaosuans,guanbians,cnt,chafen[100005];
struct node
{
    int st,a,v,ed,chaosust,chaosued;
}a[100001];
bool cmp(node a,node b)
{
    if(a.chaosust==b.chaosust)
        return a.chaosued>b.chaosued;
    return a.chaosust<b.chaosust;
}
struct work
{
    int st,ed;
}x[100001];
bool cmpp(work a,work b)
{
	if(a.st!=b.st)
		return a.st<b.st;
	return a.ed>b.ed;
}
signed main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    t=read();
    while(t--)
    {
        n=read();
        m=read();
        ed=read();
        V=read();
        for(int i=1;i<=n;i++)
        {
            a[i].st=read();
            a[i].v=read();
            a[i].a=read();
            double aa=a[i].a;
            double vv=a[i].v;
            if(a[i].a==0)
            {
                a[i].ed=ed;
                if(a[i].v>V)
                {
                    a[i].chaosust=a[i].st;
                    a[i].chaosued=a[i].ed;
                }
                else
                {
                    a[i].chaosust=a[i].chaosued=-1;
                }
                continue;
            }
            if(a[i].a>0)
                a[i].ed=ed;
            else
            {
                a[i].ed=min(a[i].st+((int)(vv*vv/(-2*aa))),ed);
            }
            if(a[i].a>0)
            {
                if(vv>V)
                {
                    a[i].chaosust=a[i].st;
                    a[i].chaosued=a[i].ed;
                }
                else
                {
                    double x=((double)(V*V)-vv*vv)/(2*aa);
                    int xx=x;
                    xx++;
                    a[i].chaosust=a[i].st+xx;
                    a[i].chaosued=a[i].ed;
                    if(a[i].chaosust>a[i].chaosued)
						a[i].chaosued=a[i].chaosust=-1;
                }
            }
            else
            {
                if(vv<=V)
                {
                    a[i].chaosust=a[i].chaosued=-1;
                }
                else
                {
                    a[i].chaosust=a[i].st;
                    double x=((double)(V*V)-vv*vv)/(2*aa);
                    int xx=x;
                    a[i].chaosued=min(a[i].st+xx,a[i].ed);
                }
            }
        }
        /*puts("");
        for(int i=1;i<=n;i++)
        {
            cout<<a[i].st<<' '<<a[i].ed<<' '<<a[i].chaosust<<' '<<a[i].chaosued<<endl;
        }*/
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            if(a[i].chaosust!=-1)
            {
                st=i;
                break;
            }
        }
        for(int i=1;i<=m;i++)
        {
            b[i]=read();
        }
        sort(b+1,b+m+1);
        for(int i=st;i<=n;i++)
        {
            int wz=lower_bound(b+1,b+m+1,a[i].chaosust)-b;
            int wzz=upper_bound(b+1,b+m+1,a[i].chaosued)-b-1;
            if(b[wz]>=a[i].chaosust&&b[wz]<=a[i].chaosued)
            {
                chaosuans++;
                if(b[wzz]>=a[i].chaosust&&b[wzz]<=a[i].chaosued)
				{
					x[++cnt]={wz,wzz};
				}
            }
        }
        printf("%lld ",chaosuans);
        sort(x+1,x+cnt+1,cmpp);
        /*for(int i=1;i<=cnt;i++)
        {
            cout<<x[i].st<<' '<<x[i].ed<<endl;
        }*/
        for(int i=2;i<=cnt;i++)
        {
            if(x[i].st<=x[i-1].ed)
            {
				x[i].st=max(x[i].st,x[i-1].st);
                x[i].ed=min(x[i].ed,x[i-1].ed);
                x[i-1].st=x[i-1].ed=-1;
            }
        }
        /*puts("worked");
        for(int i=1;i<=cnt;i++)
        {
            cout<<x[i].st<<' '<<x[i].ed<<endl;
        }*/
        for(int i=1;i<=cnt;i++)
        {
            if(x[i].st!=-1)
                guanbians++;
        }
        printf("%lld\n",m-guanbians);
        chaosuans=guanbians=cnt=0;
        memset(chafen,0,sizeof(chafen));
    }
    return 0;
}
